/**
 * This file is part of ossecdb-extjs.
 *
 * Copyright (C) 2011 Brendan Johnston
 *
 * Contact: brendan@johnston.net.au
 *
 * Project: http://code.google.com/p/ossecdb-extjs/
 *
 * License: http://www.gnu.org/licenses/gpl-3.0.html
 */

Ext.define('OssecWeb.store.Locations', {
	extend: 'Ext.data.TreeStore',

	model: 'OssecWeb.model.Location',
	
	proxy: {
		type: 'ajax',
		url: 'json-locationtree.php'
	},
	root: {
		id: 'locations',
		text: 'Locations',
		type: 'locations',
		checked: true,
		expanded: true
	},
	fields: [
		{name: 'text'},
		{name: 'type'}
	],
	listeners: {
		beforeload: function (store, operation, options) {
			// Send locationtree.php the current nodes'checked state, so that it can return correctly initialized child nodes.
			operation.params.checked = operation.node.get('checked') ? 1 : 0;
		}
	}
});